﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _5.WorkDaysInInterval
{
    class WorkDaysInInterval
    {
        private static DateTime NumberOfDays(DateTime today, int day, int month, int year, out DateTime toDateDay, out int intervalOfDays)
        {
            toDateDay = new DateTime(year, month, day);
            intervalOfDays = 0;
            intervalOfDays = Math.Abs((toDateDay - today).Days);
            if (today > toDateDay)
            {
                today = toDateDay;
                toDateDay = DateTime.Today;
            }
            return today;
        }

        private static void HolydayCheck(ref DateTime today, int intervalOfDays, ref int workdays, ref bool isHoliday)
        {
            DateTime[] holidays = 
            {               
                new DateTime(2013, 1, 1), 
                new DateTime(2013, 2, 2), 
                new DateTime(2012, 1, 1), 
                new DateTime(2012, 6, 4),
                new DateTime(2012, 2, 2), 
                new DateTime(2014, 3, 3), 
                new DateTime(2014, 4, 4),
                new DateTime(2014, 1, 18) 
            };
            for (int i = 0; i < intervalOfDays; i++)
            {
                today = today.AddDays(1);
                if (today.DayOfWeek != DayOfWeek.Saturday && today.DayOfWeek != DayOfWeek.Sunday)
                {
                    for (int j = 0; j < holidays.Length; j++)
                    {
                        if (today == holidays[j])
                        {
                            isHoliday = true;
                            break;
                        }
                    }

                    if (!isHoliday)
                    {
                        workdays++;
                    }

                    isHoliday = false;
                }
            }
            
        }
        static void Main(string[] args)
        {
            DateTime today = DateTime.Today;
            Console.WriteLine("Today is: {0:dd/MM/yyyy}",today);
            Console.WriteLine("Enter date with splitter(.,/):");
            DateTime toDate = DateTime.Parse(Console.ReadLine());
            
            int day = toDate.Day;
            int month = toDate.Month;
            int year = toDate.Year;
            
            DateTime toDateDay;
            int intervalOfDays;
            today = NumberOfDays(today, day, month, year, out toDateDay, out intervalOfDays);

            Console.WriteLine("Interval between {0} and {1} is: {2} days",today, toDateDay,intervalOfDays);
            int workdays = 0;
            bool isHoliday = false;

            HolydayCheck(ref today, intervalOfDays, ref workdays, ref isHoliday);
            Console.WriteLine("Workdays: {0} ", workdays);
        }
    }
}